package com.bpsdcs.fghvx

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context

import android.os.*

import cn.new7as.cas5s.tool.util.BatGetUxctils
import cn.new7as.cas5s.tool.phut.funs.Bjhxka
import com.blankj.utilcode.util.SPUtils
import com.google.gson.Gson

@SuppressLint("MissingPermission", "NewApi")
class BatListener {


    companion object {
        private var asdfcewmInstance: BatListener? = null

        fun getInstance(): BatListener {
            synchronized(BatListener::class.java) {
                if (asdfcewmInstance == null) {
                    asdfcewmInstance = BatListener()
                }
                return asdfcewmInstance!!
            }
        }
    }



    fun inawefasvit(activity: Activity): BatListener {
        val aasdfcasdfeUtils = BatGetUxctils()


        aasdfcasdfeUtils.initReceiver(activity)
        aasdfcasdfeUtils.setOnBatteryListener(object : BatGetUxctils.OnBattCallBack {
            override fun setBatteryResult(
                batteryHealth: String,
                maxPower: String,
                charger: String,
                batteryStatus: String,
                batteryVoltage: String,
                batteryTechnology: String?,
                batteryTemperature: String,
                isCharging: String,
                pct: Float
            ) {

                val bjhxka = Bjhxka(false, 0, false, false, "", "", "", "", "")
                bjhxka.akpxoXhtqgEmzKct = getBatteryCapacity(activity)
                bjhxka.ljdvSnrsrNqkypRpmaUmfdt = batteryHealth
                bjhxka.eazxRtiYvfqeQka = batteryTechnology!!
                bjhxka.lrteIzxnWxuyJkivu = batteryTemperature
                bjhxka.sarAegpUoszuMwcpl = batteryVoltage
                bjhxka.jobBstRchspYrnAlsb = pct.toInt()
                SPUtils.getInstance().put("batterData", Gson().toJson(bjhxka))
            }
        })
        return this
    }






    private fun getBatteryCapacity(activity: Activity): String {
        val asdfcewmPowerProfile: Any
        var asdfcewcapacity = 0.0
        val asdfcewPOWER_PROFILE_CLASS = "com.android.internal.os.PowerProfile"
        try {
            asdfcewmPowerProfile = Class.forName(asdfcewPOWER_PROFILE_CLASS)
                .getConstructor(Context::class.java)
                .newInstance(activity)
            asdfcewcapacity = Class.forName(asdfcewPOWER_PROFILE_CLASS)
                .getMethod("getBatteryCapacity")
                .invoke(asdfcewmPowerProfile) as Double
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return "$asdfcewcapacity mAh"

    }







    private fun getVersionNum(): String {
        return Build.VERSION.RELEASE
    }











}